package com.jk.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class Random {
    /**
     * 随机生成流水号
     * @author 李志
     * @create 2017-12-22 22:13
     **/
    public static String serialNumber() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String dateString = formatter.format(currentTime);
        String randomcode = "";
        for(int i=0;i<6;i++)
        {
            //52个字母与6个大小写字母间的符号；范围为91~96
            int value = (int)(Math.random()*58+65);
            while(value>=91 && value<=96)
                value = (int)(Math.random()*58+65);
            randomcode = randomcode + (char)value;

        }
        return (dateString+randomcode);

    }

    /**
     * 随机生成UUID
     * @author 李志
     * @create 2017-12-22 22:13
     **/
    public static String RandomUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * 生成当前时间
     * @author 李志
     * @create 2017-12-22 22:13
     **/
    public static String nowDate() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }
}
